import 'package:flutter/material.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/archives/app_bar.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/archives/archives_advanced_center.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/archives/archives_footer.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/archives/archives_upgrade_center.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/archives/archives_upgrade_top.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/achieves/archieves_weapon_entity.dart';
import 'package:flutter_eve_plugin/route/main.dart';
import 'package:flutter_eve_plugin/store/main.dart';
import 'package:flutter_eve_plugin/store_vm/app_vm.dart';
import 'package:flutter_eve_plugin/utils/image_util.dart';
import 'package:flutter_eve_plugin/utils/screen_util.dart';
import 'package:flutter_redux/flutter_redux.dart';
//武器升级
class ArchivesUpgradePage extends StatefulWidget {
  final String title;

  ArchivesUpgradePage({Key key, this.title}) : super(key: key);

  _ArchivesUpgradePageState createState() => _ArchivesUpgradePageState();
}

class _ArchivesUpgradePageState extends State<ArchivesUpgradePage>
    with SingleTickerProviderStateMixin {
  TabController _tabController;
  int _index = 0;

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  void initState() {
    super.initState();
    _tabController = TabController(vsync: this, length: 2);
    _tabController.addListener(() {
      setState(() {
        _index = _tabController.index;
      });
    });
  }

  @override
  Widget build(BuildContext context) {

    return StoreConnector<AppState,AppStateViewModel>(
      converter: (store) => AppStateViewModel(state: store.state),
      builder: (context ,vm) {
        ArchievesWeaponEntity weapon = vm.state?.yeXiuState?.archivesState?.archievesWeaponEntity;
        int coin = vm.state.accountInfoState?.userInfoModel?.gloryCoinCount ?? 0;
        return Container(
          decoration: BoxDecoration(
              image: DecorationImage(
                  image: AssetImage(imageUtilYeXiu('archives/icon_archives_bg@3x')),
                  fit: BoxFit.fitWidth,
                  alignment: Alignment.topCenter)),
          child: Scaffold(
            backgroundColor: Colors.transparent,
            appBar: buildArchivesAppBar(_index, '升级', '进阶', coin,(index) {
              setState(() {
                _index = index;
                _tabController.animateTo(_index);
              });
            }),
            body: TabBarView(
              controller: _tabController,
              children: <Widget>[
                SingleChildScrollView(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                      ArchivesUpgradeTopWidget(weaponEntity: weapon,),
                      ArchivesUpgradeCenterWidget(weaponEntity: weapon,)
                    ],
                  ),
                ),
                SingleChildScrollView(
                  child: Padding(
                    padding: EdgeInsets.only(top: setRatio(20)),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: <Widget>[
                        GestureDetector(
                          onTap: () {
                            Navigator.pushNamed(
                                context, RouteConstant.ArchivesQJSFormPage);
                          },
                          child: ArchivesFooterWidget(weaponEntity: weapon),
                        ),
                        ArchivesAdvancedCenterWidget(archievesWeaponEntity: weapon)
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ),
        );
      },
    );

  }
}
